package com.handinfo.android.ui.window;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWInputBox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UITyfon implements IUIWindows
{

	public DWFrame m_tyfon_frame = null;
	Bitmap m_cr_but = null;
	Bitmap m_cr_but_bianhou = null;
	Bitmap m_cr_tit = null;
	public DWButton m_but;
	public DWInputBox m_input;
	public DWBackground m_xbj;
	Bitmap m_cr_tuichu = null;
	public long m_id;
	DWButton m_quxiao;

	public void Tyfon()
	{
		if(DWControlsManager.getInstance().contains(m_tyfon_frame))
		{
			if(m_tyfon_frame != null)
			{
				DWControlsManager.getInstance().removeControl(m_tyfon_frame);
			}
		}
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH)
		{
			m_tyfon_frame = new DWFrame(550, 300);
		}
		else
		{
			m_tyfon_frame = new DWFrame(400, 200);
		}
		DWControlsManager.getInstance().addControl(m_tyfon_frame);
		m_tyfon_frame.setCentre();
		m_tyfon_frame.setClickClose(false);

		DWTitle m_tit = new DWTitle("", m_tyfon_frame);
		m_tyfon_frame.addControl(m_tit);

		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit);
		m_tit_ima.setNearAnchor(m_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_tyfon_frame.addControl(m_tit_ima);

		DWImageBox m_tuichu_ima = new DWImageBox(m_cr_tuichu);
		m_tuichu_ima.setTouchZoomIn(40, 40);
		m_tuichu_ima.setNearAnchor(m_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_tyfon_frame.addControl(m_tuichu_ima);
		m_tuichu_ima.addListener(new DWListener() {

			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(m_tyfon_frame);
			}
		});

		m_xbj = new DWBackground(m_tyfon_frame.getShowWidth() - 20, m_tyfon_frame.getShowHeight()
				- (m_tit.getShowHeight() - 20) - 20);
		m_xbj.setNearAnchor(m_tyfon_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10 + m_tit.getShowHeight() - 20);
		m_tyfon_frame.addControl(m_xbj);

		m_input = new DWInputBox(m_xbj.getShowWidth() - 30, DWFont.getDefaultFont().getHeight()+5, m_tyfon_frame);
		m_input.setNearAnchor(m_xbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 15, (m_xbj.getShowHeight() - m_cr_but.getHeight()
				- 5 - m_input.getShowHeight()) / 2);
		m_tyfon_frame.addControl(m_input);

		m_but = new DWButton("发送", m_cr_but);
		m_but.setDownImage(m_cr_but_bianhou);
		m_but.setNearAnchor(m_xbj, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -5, -10);
		m_tyfon_frame.addControl(m_but);
		m_but.addListener(m_but_lis);

		m_quxiao = new DWButton("取消", m_cr_but);
		m_quxiao.setDownImage(m_cr_but_bianhou);
		m_quxiao.setNearAnchor(m_xbj, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 5, -10);
		m_tyfon_frame.addControl(m_quxiao);
		m_quxiao.addListener(m_but_quxiao_lis);
	}

	private DWListener m_but_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			if (m_input.getText() == null || m_input.getText().equals(""))
			{
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "喊话内容不能为空。");
			}
			else if (!m_input.getText().equals("") && m_input.getText() != null)
			{
				if (m_input.getText().toString().length() > 35)
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "喊话内容字数不能超过35个汉字。");
				}
				else
				{
					DWGameManager.getInstance().getSendMessage().sendChatWorldBySpeaker(m_id, m_input.getText());
				}
			}
		}
	};
	private DWListener m_but_quxiao_lis = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			final DWMessageBox m_mb = new DWMessageBox("温馨提示", "确定取消全服喊话？", "确定", "返回");
			DWControlsManager.getInstance().addControl(m_mb);
			m_mb.addListener(new DWListener() {

				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK)
					{
						DWControlsManager.getInstance().removeControl(m_mb);
						DWControlsManager.getInstance().removeControl(m_tyfon_frame);
					}
					else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK)
					{
						DWControlsManager.getInstance().removeControl(m_mb);
					}
				}
			});
		}
	};

	public void init()
	{
		m_cr_but = UIWindows.createImage("/img/newui/anniu_6.gnp"); // /按钮的图片
		m_cr_but_bianhou = UIWindows.createImage("/img/newui/anniu_6ax.gnp");////按钮的改变后图片
		m_cr_tit = UIWindows.createImage("/img/newui/quanfuhanhua.gnp");
		m_cr_tuichu = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");///退出按钮图片
	}

	public void open(byte index)
	{
		Tyfon();
	}

	public void close(byte index)
	{
	}

	public void dispose()
	{
	}

	public void logic()
	{
	}
}
